/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import com.jnetx.javax.sip.address.AddressFactoryImpl;
import junit.framework.Assert;
import junit.framework.TestCase;

import javax.sip.header.AuthorizationHeader;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AuthorizationHeaderParserTest extends TestCase {
    public AuthorizationHeaderParserTest(String name) {
        super(name);
    }

    public void test() {
        final byte[] data = "Authorization: Digest username=\"bob\", realm=\"atlanta.example.com\", nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\", qop=\"auth-int\", opaque=\"\", uri=\"sips:ss2.biloxi.example.com\", response=\"dfe56131d1958046689d83306477ecc\"".getBytes();
        final AuthorizationHeaderParser parser = new AuthorizationHeaderParser();
        AuthorizationHeader[] headers;
        try {
            headers = parser.parse(data, 14, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 1, headers.length);
        assertEquals("The user name is wrong!", "bob", headers[0].getUsername());
        assertEquals("The realm is wrong!", "atlanta.example.com", headers[0].getRealm());
        assertEquals("The qop is wrong!", "auth-int", headers[0].getQop());
        assertEquals("The response is wrong!", "dfe56131d1958046689d83306477ecc", headers[0].getResponse());
        assertNull("The cnonce is wrong!", headers[0].getCNonce());
        assertEquals("The nonce is wrong!", "ea9c8e88df84f1cec4341ae6cbe5a359", headers[0].getNonce());
        try {
            assertEquals("The URI is wrong!", AddressFactoryImpl.createURILazily("sips:ss2.biloxi.example.com"), headers[0].getURI());
        } catch (ParseException e) {
            Assert.fail("Cannot parse the URI! " + e.getMessage());
        }
    }
}
/*
 * $Log$
 */